<template>
  <drawRightsTemp
    :successText="successText"
    :setList="setList"
    :importantText="importantText"
    :equityGroups="trialRightPackage"
    :btnText="$t('guide.now')"
    @btnClick="onOpenLogin"
    @wndClose="onClose"/>
</template>
<script>
import mixin from './mixins'
export default {
  mixins: [mixin],
  data () {
    return {
      setList: [],
      trialRightPackage: []
    }
  },
  computed: {
    successText () {
      return (this.isNewInstall ? this.$t('guide.done') : '') + (this.setList.length ? this.$t('guide.finish') : '')
    },
    importantText () {
      return `${this.$t('guide.afterLogin')}${this.setList.length ? this.$t('guide.save') : ''}${this.$t('guide.unlock')}`
    },
    statIds () {
      return this.isNewInstall ? {
        show: 2538,
        login: 2539,
        close: 2540,
        c_login: 2541,
        c_nologin: 2542,
        c_close: 2543
      } : {
        show: 2598,
        login: 2599,
        close: 2600,
        c_login: 2601,
        c_nologin: 2602,
        c_close: 2603
      }
    }
  },
  mounted () {
    this.$xz('xz_substat_action', this.statIds.show)
    this.getPackagesList({ pid: this.appInfo.allPackages }).then(res => {
      this.trialRightPackage = res.data.list || []
    })
    this.$xzAsy('xz_guider_get_all_set').then(str => {
      this.setList = str ? str.split(',').filter(it => it) : ''
    })
  },
  methods: {
    onOpenLogin () {
      this.$xz('xz_substat_action', this.statIds.login)
      this.openLogin()
    },
    onClose () {
      this.$xz('xz_substat_action', this.statIds.close)
      // this.$xz('xz_call_tips_wnd', 2)
      this.$PsMessageBox({
        customClass: 'message-white no-modal',
        distinguishCancelAndClose: true,
        center: true,
        modal: false,
        confirmButtonText: this.$t('guide.nonLogin'),
        confirmButtonClass: 'cancel',
        cancelButtonText: this.$t('guide.continue'),
        cancelButtonClass: 'el-button--primary',
        message: `${this.$t('guide.nonSave')}`,
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            this.$xz('xz_substat_action', this.statIds.c_nologin)
            this.$xz('xz_close_wnd')
          } else if (action === 'cancel') {
            this.$xz('xz_substat_action', this.statIds.c_login)
            this.openLogin()
          } else {
            this.$xz('xz_substat_action', this.statIds.c_close)
          }
          done()
        }
      })
    }
  }
}
</script>
